package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: ApArticleController
 * Description: 文章列表相关接口
 * date: 2023/8/5 0005 17:49
 *
 * @author zHan
 */
@RestController
@Slf4j
@Api(tags = "文章列表相关接口")
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 加载首页
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation("加载首页")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
//        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return apArticleService.loadHomePage(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE,
                true);
    }

    /**
     * 加载更多
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadmore")
    @ApiOperation("加载更多")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载最新
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadnew")
    @ApiOperation("加载最新")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 加载文章行为
     *
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    @ApiOperation("加载文章行为")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleBehavior(dto);
    }

}
